package com.craftplay.dao;

import com.craftplay.model.Content;
import com.craftplay.model.Recommend;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;


@Mapper
public interface RecommendMapper {
    @Delete({
            "delete from recommend",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into recommend (open_id, ",
            "user_id)",
            "values ( #{openId,jdbcType=VARCHAR}, ",
            "#{userId,jdbcType=INTEGER})"
    })
    int insert(@Param("openId") String openId, @Param("userId") int userId);

    @InsertProvider(type = RecommendSqlProvider.class, method = "insertSelective")
    int insertSelective(Recommend record);

    @Select({
            "select",
            "id, open_id, user_id",
            "from recommend",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "open_id", property = "openId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER)
    })
    Recommend selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, open_id, user_id",
            "from recommend",
            "where user_id = #{userId,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "open_id", property = "openId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER)
    })
    List<Recommend> selectByUserId(Integer userId);


    @Select({
            "select",
            "id, open_id, user_id",
            "from recommend",
            "where open_id = #{openId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "open_id", property = "openId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER)
    })
    Recommend selectByOpenId(String openId);

    @UpdateProvider(type = RecommendSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Recommend record);

    @Update({
            "update recommend",
            "set open_id = #{openId,jdbcType=VARCHAR},",
            "user_id = #{userId,jdbcType=INTEGER}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Recommend record);

}